package com.ysg.widget.dialog;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import com.ysg.R;
import com.ysg.base.BaseDialog;
import com.ysg.http.data.entity.ticket.TicketPriceEntity;
import com.ysg.utils.YStringUtil;

/**
 * 门票
 */
public class TicketDialog extends BaseDialog {
    public interface OnTicketListener{
        void onWechatClick();
        void onAlipayClick();
    }
    private OnTicketListener listener;
    public void setOnTicketListener(OnTicketListener listener){
        this.listener = listener;
    }

    private TextView tvPrice;
    private View tvWechat, tvAlipay;
    private TicketPriceEntity entity;

    public TicketDialog(Context context, TicketPriceEntity priceEntity) {
        super(context);
        this.entity = priceEntity;
    }

    @Override
    public int getLayoutId() {
        return R.layout.dialog_ticket;
    }

    public void initView() {
        setWidthScale(1f);
        setCancelable(false);
        setCanceledOnTouchOutside(false);
        Window window = getWindow();
        window.setGravity(Gravity.BOTTOM);

        tvPrice = findViewById(R.id.tvPrice);
        tvWechat = findViewById(R.id.tvWechat);
        tvAlipay = findViewById(R.id.tvAlipay);
    }

    @Override
    public void initData() {
        if (YStringUtil.isNotEmpty(entity.getPrice())){
            tvPrice.setText(getContext().getResources().getString(R.string.currency) + entity.getPrice());
        }
    }

    @Override
    public void initListener() {
        tvWechat.setOnClickListener((v -> {
            dismiss();
            if (listener != null){
                listener.onWechatClick();
            }
        }));
        tvAlipay.setOnClickListener((v -> {
            dismiss();
            if (listener != null){
                listener.onAlipayClick();
            }
        }));
    }
}
